package com.eam.job.controller;

import com.eam.common.controller.BaseController;
import com.eam.common.domain.EamTask;
import com.eam.common.service.IEamTaskService;
import com.eam.common.utils.ExcelUtil;
import com.eam.core.annotation.Log;
import com.eam.core.core.AjaxResult;
import com.eam.core.core.page.TableDataInfo;
import com.eam.core.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 盘点任务Controller
 * 
 * @author eam
 * @date 2022-03-14
 */
@Api("盘点任务接口")
@RestController
@RequestMapping("/eam/task")
public class EamTaskController extends BaseController
{
    @Autowired
    private IEamTaskService eamTaskService;

    /**
     * 查询盘点任务列表
     */
    @ApiOperation("盘点任务列表")
    @PreAuthorize("@ss.hasPermi('eam:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(EamTask eamTask)
    {
        startPage();
        List<EamTask> list = eamTaskService.selectEamTaskList(eamTask);
        return getDataTable(list);
    }

    /**
     * 导出盘点任务列表
     */
    @PreAuthorize("@ss.hasPermi('eam:task:export')")
    @Log(title = "盘点任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EamTask eamTask)
    {
        List<EamTask> list = eamTaskService.selectEamTaskList(eamTask);
        ExcelUtil<EamTask> util = new ExcelUtil<EamTask>(EamTask.class);
        util.exportExcel(response, list, "盘点任务数据");
    }

    /**
     * 获取盘点任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('eam:task:query')")
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") Long taskId)
    {
        return AjaxResult.success(eamTaskService.selectEamTaskByTaskId(taskId));
    }

    /**
     * 新增盘点任务
     */
    @PreAuthorize("@ss.hasPermi('eam:task:add')")
    @Log(title = "盘点任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EamTask eamTask)
    {
        return toAjax(eamTaskService.insertEamTask(eamTask));
    }

    /**
     * 修改盘点任务
     */
    @PreAuthorize("@ss.hasPermi('eam:task:edit')")
    @Log(title = "盘点任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EamTask eamTask)
    {
        return toAjax(eamTaskService.updateEamTask(eamTask));
    }

    /**
     * 删除盘点任务
     */
    @PreAuthorize("@ss.hasPermi('eam:task:remove')")
    @Log(title = "盘点任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable Long[] taskIds)
    {
        return toAjax(eamTaskService.deleteEamTaskByTaskIds(taskIds));
    }
}
